import request from "@/utils/request";
import type { SpuImageData, SpuSaleAttrData } from "./spu";
export interface SkuImageData {
  id?: number;
  skuId?: number;
  imgName: string;
  imgUrl: string;
  spuImgId: number;
  isDefault: string;
}
export interface SkuAttrValueData {
  id?: number;
  attrId: number | string;
  valueId: number | string;
  skuId?: number;
  attrName?: string;
  valueName?: string;
}
export interface SkuSaleAttrValueData {
  id?: number;
  skuId?: number;
  spuId?: number;
  saleAttrValueId: number | string;
  saleAttrId: number | string;
  saleAttrName?: string;
  saleAttrValueName?: string;
}
export interface SkuData {
  id?: number;
  spuId: number;
  price: number;
  skuName: string;
  skuDesc: string;
  weight: string;
  tmId: number;
  category3Id: number;
  skuDefaultImg: string;
  isSale?: number;
  createTime?: string;
  skuImageList: SkuImageData[];
  skuAttrValueList: SkuAttrValueData[];
  skuSaleAttrValueList: SkuSaleAttrValueData[];
}

type SkuPageListData = {
  records: SkuData[];
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
};
export default {
  // 下架商品
  // GET /admin/product/cancelSale/{skuId}
  cancelSale(skuId: number) {
    return request.get<any, null>(`/admin/product/cancelSale/${skuId}`);
  },
  // GET /admin/product/onSale/{skuId}
  onSale(skuId: number) {
    return request.get<any, null>(`/admin/product/onSale/${skuId}`);
  },
  //  删除sku
  // DELETE /admin/product/deleteSku/{skuId}
  deleteSku(skuId: number) {
    return request.delete<any, null>(`/admin/product/deleteSku/${skuId}`);
  },
  //  根据spu的id去查找这个spu中所有的sku的列表
  // GET /admin/product/findBySpuId/{spuId}
  findBySpuId(spuId: number) {
    return request.get<any, SkuData[]>(`/admin/product/findBySpuId/${spuId}`);
  },
  //  根据sku的id获取sku详情信息
  // GET /admin/product/getSkuById/{skuId}
  getById(skuId: number) {
    return request.get<any, SkuData>(`/admin/product/getSkuById/${skuId}`);
  },
  // 下面两个是根据关键字sku的详细信息单个，和多个
  // GET /admin/product/inner/findSkuInfoByKeyword/{keyword}
  // findSkuInfoByKeyword
  // POST /admin/product/inner/findSkuInfoBySkuIdList
  // findSkuInfoBySkuIdList

  //   获取sku的分页列表
  // GET /admin/product/list/{page}/{limit}
  // index
  getPageList(page: number, limit: number) {
    return request.get<any, SkuPageListData>(
      `/admin/product/list/${page}/${limit}`
    );
  },

  // POST /admin/product/saveSkuInfo
  // saveSkuInfo
  saveSkuInfo(sku: SkuData) {
    return request.post<any, null>("/admin/product/saveSkuInfo", sku);
  },
  // GET /admin/product/spuImageList/{spuId}
  getSpuImageList(spuId: Number) {
    return request.get<any, SpuImageData[]>(
      `/admin/product/spuImageList/${spuId}`
    );
  },
  // 根据spu的id获取对应spu的销售属性列表
  // GET /admin/product/spuSaleAttrList/{spuId}
  getSpuSaleAttrList(spuId: number) {
    return request.get<any, SpuSaleAttrData[]>(
      `/admin/product/spuSaleAttrList/${spuId}`
    );
  },
  // POST /admin/product/updateSkuInfo
};
